package com.weng.apistarter.validator.api;

import com.weng.apistarter.validator.model.Car;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.validator.Validator;
import com.weng.framework.validator.annotation.NotEmpty;
import com.weng.framework.validator.annotation.StrNotNull;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.ConstraintViolation;
import javax.validation.Valid;
import java.util.Set;


/**
* 参数校验示例
* @author wengzhonghui
* @date: 2021-06-22 15:29:12
*/
@Slf4j
@RestController
@RequestMapping("/validator")
@Api(value = "参数校验api", tags = {"参数校验接口"})
public class ValidatorSampleApi {

    @ApiOperation(value = "get校验对象内的参数", notes = "")
    @GetMapping(value = "/get")
    public ResponseData get(@Valid Car c){
        return ResponseData.success(c);
    }

    @ApiOperation(value = "post json校验对象内的参数", notes = "")
    @PostMapping(value = "/post")
    public ResponseData post(@Valid @RequestBody Car c){
        return ResponseData.success(c);
    }

    @ApiOperation(value = "单个值校验【不支持这种场景,只支持bean内部使用注解】", notes = "")
    @GetMapping(value = "/single")
    public ResponseData single(@NotEmpty @Valid String val){
        return ResponseData.success(val);
    }

}